/**
 * Copyright (C), 2015-2020, 云帐房
 * FileName: SqlRemoteDataSource
 * Author:   cjz
 * Date:     2020/5/14 下午6:16
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.yzf.wisecoder.remotedata;

import com.yzf.cframework.common.db.DBHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;

import java.util.List;
import java.util.Map;

/**
 * @ClassName : SqlRemoteDataSource
 * @Description : Sql 远程数据
 * @Author : cjz
 * @Date: 2020-05-14 18:16
 */
@Slf4j
public class SqlRemoteDataSource extends AbstractRemoteDataSource{


    public SqlRemoteDataSource(RemoteInfo remoteInfo) {
        super(remoteInfo);
    }

    @Override
    public AbstractRemoteDataSource execute() {

        DBHelper dbHelper = DBHelper.getInstance(remoteInfo.getUrl()
                , remoteInfo.getUserName()
                , remoteInfo.getPassword());

        try {
            result = dbHelper.executeQuery(remoteInfo.getExecute(), null);
        } catch (Exception e) {
            log.error("execute sql error:{}-{}",remoteInfo,e.getMessage());
            e.printStackTrace();
        }
        return this;
    }

    @Override
    public List<Map> result() {
        return (List<Map>) result;
    }
}
